package com.paddyi.controller;

import com.paddyi.commons.http.HttpResult;
import com.paddyi.commons.page.MyPage;
import com.paddyi.model.RoleResource;
import com.paddyi.service.IRoleResourceService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 角色资源 (RoleResource)
 * @author paddy
 * @since  2019-05-10 02:53:26
 */
@RestController
@RequestMapping("roleResource")
public class RoleResourceController extends BaseController {

	@Reference(version = "${demo.service.version}")
	private IRoleResourceService roleResourceService;

	/**
	 * 保存角色资源
	 * @param record
	 * @return
	 */	
	@PostMapping(value="/save")
	public HttpResult save(@RequestBody RoleResource record) {
		return HttpResult.ok(roleResourceService.save(record));
	}

    /**
     * 删除角色资源
     * @param records
     * @return
     */
	@PostMapping(value="/delete")
	public HttpResult delete(@RequestBody List<Long> records) {
		return HttpResult.ok(roleResourceService.removeByIds(records));
	}

    /**
     * 基础分页查询,条件查询只支持等于，如果想要更高级的功能，比如大于小于等等，请自己写吧
     * @param page
     * @return
     */    
	@PostMapping(value="/findPage")
	public HttpResult findPage(@RequestBody MyPage<RoleResource> page) {
		return HttpResult.ok(roleResourceService.page(page));
	}
	
    /**
     * 根据主键查询
     * @param id
     * @return
     */ 	
	@GetMapping(value="/findById")
	public HttpResult findById(@RequestParam Long id) {
		return HttpResult.ok(roleResourceService.getById(id));
	}
}
